<?php
namespace Common\Library;

/**
 * 站点对象工厂
 * Class CompanyModel
 * @package Common\Library
 */
class SiteDao {

    /**
     * 通过数组数据构造对象
     * @param array $data
     * @return SiteModel
     */
    public static function FetchByData(array $data){
        $site = new SiteModel();
        $site->id = $data['si_id'];
        $site->domain = $data['si_domain'];
        $site->name = $data['si_name'];
        $site->logo = $data['si_logo'];
        $site->skin = $data['si_skin'];
        return $site;
    }

    /**
     * 通过ID获取
     */
    public static function FetchByCompany($key){
        $companyModel = D('site');
        $data = $companyModel->where(['cp_id'=>$key])->select();
        return self::FetchByData($data[0]);
    }

    /**
     * 通过ID获取
     */
    public static function FetchByID($key){
        $companyModel = D('site');
        $data = $companyModel->where(['si_id'=>$key])->select();
        return self::FetchByData($data[0]);
    }

    /**
     * 通过Domain获取
     */
    public static function FetchByDomain($key){
        $companyModel = D('company');
        $data = $companyModel->where(['cp_domain'=>$key])->select();
        return self::FetchByData($data[0]);
    }

    /**
     * 通过Name获取
     */
    public static function FetchByName($key){
        $companyModel = D('company');
        $data = $companyModel->where(['cp_name'=>$key])->select();
        return self::FetchByData($data[0]);
    }


}